#define _CRT_SECURE_NO_WARNINGS	1
class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int n = nums.size();
        int tmp = 0, ret = 0;
        for (int left = 0, right = 0; right < n; right++)
        {
            if (nums[right] == 0) tmp++;
            while (tmp > k)
            {
                if (nums[left++] == 0)
                {
                    tmp--;
                }
            }
            ret = max(ret, right - left + 1);
        }
        return ret;
    }
};